Incorporating the QuickTime routines into the structure of a Windows application program is relatively straightforward. You need to follow the basic steps outlined here to build a simple QuickTime capability into your Windows program. Names in parentheses are those of the relevant QTML routines.
Listing 1 illustrates, in skeletal form, how these steps fit into the structure of a typical Windows application program. In the next chapter, we'll discuss each of these steps in turn, along with the related QTML concepts that you need to understand in order to use QuickTime effectively.
Listing 1 Skeleton of a Windows program using QuickTime
// Resource identifiers
·
·
#define IDM_OPEN 101
·
·
// Global variables
char movieFile[255]; // Name of movie file
Movie theMovie; // Movie object
MovieController theMC; // Movie controller
///////////////////////////////////////////////////////////////////////////////////////
int CALLBACK WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
·
·
InitializeQTML(0); // Initialize QTML
EnterMovies(); // Initialize QuickTime
·
·
///////////////////////////////////////////////////////////////////////////////
// Main message loop
·
·
//
///////////////////////////////////////////////////////////////////////////////
·
·
ExitMovies(); // Terminate QuickTime
TerminateQTML(); // Terminate QTML
} /* end WinMain */
///////////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
MSG winMsg;
EventRecord qtmlEvent;
int wmEvent, wmId;
// Fill in contents of MSG structure
·
·
NativeEventToMacEvent (&winMsg, &qtmlEvent);// Convert message to a QTML event
MCIsPlayerEvent (theMC, (const EventRecord *) &qtmlEvent);
// Pass event to movie controller
switch ( message )
{
case WM_CREATE:
CreatePortAssociation (hWnd, NULL); // Register window with QTML
break;
case WM_COMMAND:
wmEvent = HIWORD(wParam); // Parse menu selection
wmId = LOWORD(wParam);
switch ( wmId )
{
case IDM_OPEN:
CloseMovie (); // Close previous movie, if any
if ( GetFile (movieFile) ) // Get file name from user
OpenMovie (hWnd, movieFile); // Open the movie
break;
·
·
default:
return DefWindowProc (hWnd, message,
wParam, lParam);
} /* end switch ( wmId ) */
break;
case WM_CLOSE:
DestroyPortAssociation (hWnd); // Unregister window with QTML
break;
·
·
default:
return DefWindowProc (hWnd, message, wParam, lParam);
} /* end switch ( message ) */
return 0;
} /* end WndProc */
///////////////////////////////////////////////////////////////////////////////////////
BOOL GetFile (char *movieFile)
{
OPENFILENAME ofn;
// Fill in contents of OPENFILENAME structure
·
·
if ( GetOpenFileName(&ofn) ) // Let user select file
return TRUE;
else
return FALSE;
} /* end GetFile */
///////////////////////////////////////////////////////////////////////////////////////
void OpenMovie (HWND hwnd, char fileName[255])
{
short theFile = 0;
FSSpec sfFile;
char fullPath[255];
SetGWorld ( (CGrafPtr)GetNativeWindowPort( hwnd ), nil); // Set graphics port
strcpy (fullPath, fileName); // Copy full pathname
c2pstr (fullPath); // Convert to Pascal string
FSMakeFSSpec (0, 0L, fullPath, &sfFile); // Make file-system
// specification record
OpenMovieFile (&sfFile, &theFile, fsRdPerm); // Open movie file
NewMovieFromFile (&theMovie, theFile, nil, // Get movie from file
nil, newMovieActive, nil);
CloseMovieFile (theFile); // Close movie file
theMC = NewMovieController (theMovie, ... ); // Make movie controller
·
·
} /* end OpenMovie */
///////////////////////////////////////////////////////////////////////////////////////
void CloseMovie (void)
{
if ( theMC ) // Destroy movie controller, if any
DisposeMovieController (theMC);
if ( theMovie ) // Destroy movie object, if any
DisposeMovie (theMovie);
} /* end CloseMovie */
| Previous | Chapter Contents | Chapter Top | Roadmap | Next |